import { Component, OnInit,ViewChild,Input,Output,EventEmitter } from '@angular/core';
import {APARTMENT} from "../../service/apartment.service";
import {ROUTE} from "../../service/route.service";
import {BookingHouseModalViewComponent} from "../booking-house-modal-view/booking-house-modal-view.component";
declare var $:any;
@Component({
  selector: 'layout-type-modal-view',
  templateUrl: './layout-type-modal-view.component.html',
  styleUrls: ['./layout-type-modal-view.component.scss']
})
export class LayoutTypeModalViewComponent implements OnInit {

  @ViewChild(BookingHouseModalViewComponent) public bookingModal:any;
  @Input('showModal') public isModalShown:boolean = false;
  @Output('modalClose') public modalClose = new EventEmitter();

  public apartmentId:number;
  // 默认banners，后台若有将会被替换成后台的。
  banners:any=[
    {id:1,url:'assets/images/brand-story.jpg'},
    {id:2,url:'assets/images/brand-story.jpg'},
    {id:3,url:'assets/images/brand-story.jpg'},
    {id:4,url:'assets/images/brand-story.jpg'}
  ];
  layoutDetail:any={};
  mainUrl:string;

  constructor(private apartmentApi:APARTMENT,private route:ROUTE) {
  }

  loadLayoutDetail(layoutId:number){
    this.apartmentApi.getLayoutDetail(layoutId,(res:any)=>{
      if(res.banner.length!=0){
        this.banners=res.banner;
        this.mainUrl = this.banners[0].url
      }
      this.layoutDetail = res;
      // console.log(this.layoutDetail);
    })
  }

  goToRentingView(item:any){
    console.log(item);
    if(item){
      this.route.gotoRenting(item);
    }
  }
  doSomething(item:any){
    // console.log(item);
  }
  showBookingModal(){
    this.bookingModal.showModal();
    this.onHidden();
  }
  public showModal(item:any):void {
    this.isModalShown = true;
    this.apartmentId = item.apartmentId;
    this.loadLayoutDetail(item.id);
  }
  public onHidden(): void {
    this.isModalShown = false;
  }

  ngOnInit() {
  }

}
